<template>
    <!-- 登录界面 -->
    <div class="form-all">

        <!-- 标题与表单输入框 -->
        <div class="form-wrapper">
            <!-- logo/标题部分 -->
            <div class="header">
                <img src="@/assets/logo.png" alt="">
            </div>
            <!-- 表单 -->
            <div class="input-wrapper">
                <div class="border-wrapper">
                    <input type="text" placeholder="请输入管理员账号" class="border-item" autocomplete="off"
                        v-model="formData.admin" />
                </div>
                <div class="border-wrapper">
                    <input type="password" placeholder="请输入管理员密码" class="border-item" autocomplete="off"
                        v-model="formData.password" />
                </div>
            </div>
            <!-- 登录按钮 -->
            <div class="action">
                <div class="btn" @click="login">登录</div>
            </div>
            <!-- 第三方登录 -->
            <div class="icon-wrapper">
                <i class="el-icon-edit"></i>
                <i class="el-icon-chat-dot-round"></i>
                <i class="el-icon-mobile-phone"></i>
            </div>
        </div>
    </div>
</template>
  
<script>
import { login } from '@/http/api';
export default {

    data() {
        return {
            formData: {
                admin: '',
                password: ''
            }
        }
    },
    methods: {
        login() {
            // 非空校验
            if (this.formData.admin.length == 0) {
                this.$message.error('账号不能为空！')
                return
            }
            if (this.formData.password.length == 0) {
                this.$message.error('密码不能为空！')
                return
            }
            // 封装body信息
            const data = {
                d_admin: this.formData.admin,
                d_pwd: this.formData.password
            }
            // 请求后端服务器
            login(data).then(res => {
                console.log(res);
                if (res?.data?.code == 200) {
                    sessionStorage.setItem('token', res?.data?.data?.token)
                    sessionStorage.setItem('admin', JSON.stringify(res?.data?.data))
                    // 消息提示
                    this.$message({
                        message: res?.data?.msg,
                        type: 'success'
                    })
                    this.$router.replace('/home')
                } else {
                    this.$message.error(res.data.msg)
                }
            }).catch(err => {
                console.log('登录失败返回');
            })
        }
    }

};
</script>
  
<style>
* {
    margin: 0;
    padding: 0;
}

.form-all {
    height: 100%;
    font-family: JetBrains Mono Medium;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: #b3d8ff;
    background-size: 100% 100%;
    position: relative;
}

.header {
    position: relative;
    text-align: center;
}

.form-wrapper {
    width: 300px;
    background-color: rgba(41, 45, 62, 0.8);
    color: #fff;
    border-radius: 10px;
    padding: 25px;
}

.form-wrapper .header img {
    width: 65%;
    margin-bottom: 20px;
}

.form-wrapper .input-wrapper input {
    background-color: rgb(41, 45, 62);
    border: 0;
    width: 100%;
    text-align: center;
    font-size: 15px;
    color: #fff;
    outline: none;
}

.form-wrapper .input-wrapper input::placeholder {
    text-transform: uppercase;
}

.form-wrapper .input-wrapper .border-wrapper {
    background-image: linear-gradient(to right, #fff, #0eb4dd);
    width: 100%;
    height: 50px;
    margin-bottom: 20px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.form-wrapper .input-wrapper .border-wrapper .border-item {
    height: calc(100% - 4px);
    width: calc(100% - 4px);
    border-radius: 30px;
}

.form-wrapper .action {
    display: flex;
    justify-content: center;
}

.form-wrapper .action .btn {
    width: 100%;
    height: 46px;
    text-transform: uppercase;
    border: 2px solid #0e92b3;
    text-align: center;
    line-height: 46px;
    border-radius: 30px;
    cursor: pointer;
    user-select: none;
}

.form-wrapper .action .btn:active {
    background-image: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);
}

.form-wrapper .icon-wrapper {
    text-align: center;
    width: calc(100% - 50px);
    margin: 0 auto;
    margin-top: 20px;
    border-top: 1px dashed rgb(146, 146, 146);
    padding: 20px;
}

.form-wrapper .icon-wrapper i {
    font-size: 20px;
    color: rgb(187, 187, 187);
    cursor: pointer;
    border: 1px solid #fff;
    padding: 5px;
    border-radius: 20px;
    margin: 3px;
}

.form-wrapper .icon-wrapper i:active {
    background-color: #0e92b3;
}
</style>